<template>
  <div class="slider">
    <el-carousel trigger="click" :height="carHeight + 'px'">
      <el-carousel-item v-for="(item,index) in carouselList" :key="index" :label="item.tag">
        <div class="background_cont" :style="{background:`url(${item.image})`,backgroundSize:'cover',backgroundPosition:'center'}"></div>
        <div class="bgCont container">
          <h1>{{item.content}}</h1>
          <p>{{item.text}}</p>
          <button><a href="#">{{item.button_txt}}</a></button>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  data () {
    return {
      carouselList: [],
      carHeight: 992
    }
  },
  async created () {
    const { data: res } = await this.$http.get('rotations')
    this.carouselList = res.data
    this.onresizeWidth()
  },
  mounted () {
    window.onresize = this.onresizeWidth
  },
  methods: {
    onresizeWidth () {
      const width = document.documentElement.clientWidth
      return this.$nextTick(() => {
        if (width <= 992) {
          this.carHeight = 620
        } else if (width <= 768) {
          this.carHeight = 600
        } else {
          this.carHeight = 992
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.background_cont{
  width: 100%;
  height: 100%;
}
.bgCont{
  width: 100%;
  position: absolute;
  left: 5%;
  top:50%;
  transform: translateY(-50%);
  z-index: 150;
  h1{
    width: 36%;
    font-size: 2.5rem;
    color: #000;
  }
  p{
    font-size: 0.7rem;
    color: #000;
    font-weight: 400;
    margin: 0.6rem 0 1.6rem 0;
    transform: translateY(1.6rem);
  }
  button{
    min-width: 5.5rem;
    height: 1.7rem;
    text-align: center;
    transition: all 0.5s;
    border-radius: 30px;
    line-height: 1.7rem;
    font-size: 0.4rem;
    font-weight: 500;
    background-color: #3d3d3d;
    border: none;
    cursor: pointer;
    margin-top: 0.9rem;
    a{
      color: #fff;
    }
  }
}
.bgCont button:hover{
  background-color: #eb2323;
}
@media screen and (max-width:992px){
    .bgCont{
      h1{
        width: 80%;
        font-size: 2rem;
      }
  }
}
@media screen and (max-width:992px){
  .bgCont{
    button{
      min-width: 8rem;
      height: 2.4rem;
    }
  }
}
@media screen and (max-width:576px){
  .bgCont{
    h1{
      font-size: 1.5rem;
    }
    p{
      width: 80%;
      margin: 0.6rem 0 2.6rem 0;
    }
  }
}
</style>
